package ifosup.marie.url;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class ClassMainUrl 
{

	public static void main(String[] args) 
	{
		try 
		{
			URL url = new URL("http://www.google.fr/search?q=url&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:fr:official&client=firefox-a&source=hp&channel=np");
			URLConnection connection = url.openConnection();
			File fichier = new File("C:/Users/STAGIAIRE4/Desktop","fichier.txt");
			Writer writer = new FileWriter(fichier);

			Map<String, List<String>> header = connection.getHeaderFields();
			Set<String> keys = header.keySet();
			for (String s : keys)
			{
				writer.write(s + " : " + header.get(s) + "\r\n");
			}
			writer.close();
		} 
		catch (MalformedURLException e) 
		{
			e.printStackTrace();
		} 
		catch (IOException e) 
		{
			e.printStackTrace();
		}
	}

}
